﻿#include "stdafx.h"
#include "ClassMemberGen.h"
#include "ClassInstanceType.h"

using namespace llvm;
Value * ClassMemberGen::generateCode(Module *m, Function *func, IRBuilder<>&builder)
{
	Value* c;
	if (value) {
		c = value->generateCode(m, func, builder);
	}
	else {
		auto &a = *(func->arg_begin());
		c = &a;
	}

	assert(c->getType()->isPointerTy());

	if (index < 0) return c;

	auto* x = classType->llvmType(m->getContext());
	return builder.CreateStructGEP(x, c, index, name);
}
